<template>
<div class="app-container">


    <div class="top-box clearfix">
        <div class="top-left clearfix"></div>
        <div class="top-right clearfix">
            <el-button type="primary" @click="toAdd()">添加</el-button>
        </div>
    </div>

    <div class="resource-group-table-box">
        <table class="z-table" style="width: 100%">
            <thead>
            <tr>
                <th style="width: 150px">ID</th>
                <th>名称</th>
                <th>备注</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <tr v-for="g in resourceGroups">
                <td>{{g.id}}</td>
                <td>{{g.name}}</td>
                <td>{{g.remark}}</td>
                <td>
                    <a class="z-label" @click="toEdit(g.id)">编辑</a>
                    <a class="z-label danger" @click="deleteById(g.id)">删除</a>
                </td>
            </tr>
            </tbody>
        </table>


        <!--
        <div class="pagination-box">
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="pageBean.pageCount"
                :page-sizes="[10, 20, 30, 50,80]"
                :page-size="queryParams.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="pageBean.total">
            </el-pagination>
        </div>-->
    </div>
</div>
</template>

<script>
    import '@/styles/form-box.css'
    import resourceGroupApi from '../../api/resourceGroup'
    import {Message, MessageBox} from 'element-ui'



    //components
    import httpMethod from '@/components/HttpMethod/index'


    export default {
        name: "resource-group-manager",
        data:function () {
            return {
                resourceGroups:[],
            }
        },
        mounted:function () {
            this.refreshTable();
        },
        methods:{
            refreshTable(){
                //加载所有resource
                const _this = this;
                resourceGroupApi.findAll()
                    .then(function (data) {
                        _this.resourceGroups = data;
                    })
            },
            toAdd() {
                // resource-group-manager-add
                this.$router.push('/security/resource-group-manager-add')
            },
            deleteById(resourceGroupId){
                console.log("准备删除ID"+resourceGroupId)
                const _this = this;
                MessageBox.confirm('删除该组，将设置当前组下资源组值为空', '确定删除', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type: 'warning'
                        }).then(() => {
                            resourceGroupApi.delete(resourceGroupId)
                                .then(function (data) {
                                    if (data.success){
                                        Message.success("删除组成功")
                                        _this.refreshTable();
                                        return;
                                    }
                                    Message.error("删除失败")
                                }).catch(function () {
                                    Message.error("删除失败")
                                })
                        })

            },
            toEdit:function (id) {
                this.$router.push({path:'/security/resource-group-manager-edit/'+id})
            }
        },
        components:{
            'http-method':httpMethod
        }
    }
</script>

<style scoped>

</style>
